cc.Class({
    extends: cc.Component,

    properties: {
        spIcon: cc.Sprite,
        spArrayIcon: [cc.SpriteFrame],
    },

    onLoad() {
        //
        this.RigidBody = this.getComponent(cc.RigidBody);
        let velocity = this.RigidBody;
        velocity.linearVelocity.x = 0;
        velocity.linearVelocity.y = 0;
        this.RigidBody = velocity;
    },

    start() {

    },

    //初始化
    initBullet(id, icon, rateX, rateY, pos) {
        this.id = id;
        this.spIcon.spriteFrame = this.spArrayIcon[icon - 1];
        this.node.setPosition(pos);
        this.RigidBody.linearVelocity = cc.v2(rateX, rateY);
        //
    },

    bulletBoomOther(contact, selfCollider, otherCollider) {
        // console.log('子弹碰撞事件');
        //谁碰撞
        let bulletNode = selfCollider.node;
        const id = selfCollider.node.getComponent('bullet').id;
        if (ICPC.bulletManager.isStaticBullet(id)) return;
        //
        switch (otherCollider.tag) {
            case ICPC.CONST.TAG.TAG_WELL: {
                ICPC.bulletManager.killBullet(id);
                break;
            }
            case ICPC.CONST.TAG.TAG_ENEMY: {
                const enemyId = otherCollider.node.getComponent('enemy').id;
                //子弹消失
                ICPC.bulletManager.killBullet(id);
                //爆炸特效
                let effectFlag = {effectName: 'death1', effectInfo: null};
                ICPC.effectManager.addEffect(effectFlag, bulletNode.getPosition());
                //血量减少
                ICPC.enemyManager.onBoomForId(enemyId);
                //
                break;
            }
            default:
                break;
        }
    },

    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {
        // console.log('buttle 只在两个碰撞体开始接触时被调用一次', contact, selfCollider, otherCollider);
        //
        this.bulletBoomOther(contact, selfCollider, otherCollider);
    },

    // 只在两个碰撞体结束接触时被调用一次
    onEndContact: function (contact, selfCollider, otherCollider) {
        // console.log('buttle 只在两个碰撞体结束接触时被调用一次');
    },

    // 每次将要处理碰撞体接触逻辑时被调用
    onPreSolve: function (contact, selfCollider, otherCollider) {
        // console.log('buttle 每次将要处理碰撞体接触逻辑时被调用');
    },

    // 每次处理完碰撞体接触逻辑时被调用
    onPostSolve: function (contact, selfCollider, otherCollider) {
        // console.log('buttle 每次处理完碰撞体接触逻辑时被调用');
    }
    // update (dt) {},
});
